module.exports = {
	html(compentName) {
		return `<div id="${compentName}">
	<form-editor ref="formEditor"
		:action="action"
		:colWidth="colWidth"
		:formItems="formItems"
		:itemWidth="itemWidth"
		:formParams="formParams"
		@handle-save="handleSave"
		@handle-reset="handleReset">
	</form-editor>
</div>`;
	},

	javascript(compentName, params) {
		const defaultFormItems = `[
			{label: "编号", kind: "input", prop: "id", isEdit: false, disabled: true}
		]`;
		const formItems = JSON.stringify(params.formItems ? params.formItems : defaultFormItems);
		return `export default {
	name: "${compentName}",
	data() {
		return {
			action: "${params.action}",
			colWidth: ${params.colWidth},
			itemWidth: ${params.itemWidth},
			formItems: ` + formItems + `,
			formParams: {}
		};
	},
	created() {
		this.initData(this.$route);
	},
	methods: {
		handleSave(formParams) {
			this.formParams = formParams;
			console.log(this.formParams);
		},
		handleReset() {
			this.formParams = {};
		},
		initData(route) {
			this.formParams = this.formHandler.handleParams(route);
			this.action = this.formHandler.handleAction(route);
			this.formHandler.updateEditStatus(this.action, this.formItems);
		}
	},
	watch: {
		//监听路由的变化来实现添加或切换tab
		$route(to) {
			this.initData(to);
		}
	}
};`;
	}
};
